package com.koron.css2.meterService.impl;

import com.koron.css2.common.dto.AttachmentDto;
import com.koron.css2.common.service.AbstractExportExcel;
import com.koron.css2.meterService.bean.query.MsChgPlanDetailQueryBean;
import com.koron.css2.meterService.dto.MsChgPlanDetailDto;
import com.koron.css2.meterService.mapper.MsChgPlanDetailMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.css2.serviceManage.vo.DictionaryVO;
import com.koron.util.Tools;
import org.koron.ebs.mybatis.SessionFactory;

import java.util.List;

/**
 * 拆表历史导出
 * @author 
 *
 */
public class MsChgHistoryExport extends AbstractExportExcel{

	@Override
	public AttachmentDto getAttachment(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MsChgPlanDetailQueryBean bean = JsonUtils.objectToPojo(req.getData(), MsChgPlanDetailQueryBean.class);
		MsChgPlanDetailMapper mapper = factory.getMapper(MsChgPlanDetailMapper.class);	
		List<MsChgPlanDetailDto> list = mapper.selectList(bean);
		List<DictionaryVO> dvo = Tools.listDicByCode(factory, "OMD");
		for(MsChgPlanDetailDto detail : list) {
			if(detail.getOldHandleWay() != null) {
				for(DictionaryVO vo: dvo) {
					if(vo.getValue().equals(detail.getOldHandleWay())) {
						detail.setOldHandleWay(vo.getName());
						break;
					}
				}
			}				
		}
		AttachmentDto attachment = new AttachmentDto();
		attachment.setBtlTemplate("MsChgHistoryExport.btl");
		attachment.setFileTemplate("MsChgHistoryExport.xlsx");
		attachment.setData(list);
		attachment.setFileType("excel");
		attachment.setFilename("拆表历史");
		return attachment;
	}

}
